<template>
	<div class="teamplate-login">
		<div class="login-wrap clearfix">
			<div class="logo pull-left">
				<i class="iconfont icon-logo"></i>
				<div class="d1">汇芈智慧医药零售云</div>
				<div class="d2">智慧管理|科学统计|智慧销售</div>
			</div>
			<div class="login-box pull-right">
				<div class="title">欢迎</div>
				<form action="">
					<ul>
						<li><span>用户名</span><input type="text" v-model="username"></li>
						<li><span>密码</span><input type="password" v-model="password"></li>
					</ul>
					<div class="submits"><input type="button" value="登录" @click="onSubmit"></div>
				</form>
			</div>
		</div>
	</div>
</template>

<script>
    import bus from "../api/eventBus";
    import {
        setUi,
        setUserInfo,
        setpopPerfect
    } from "../vuex/actions";
    import {
        ui,
        userInfo,
        popPerfect
    } from "../vuex/getters";
    export default {
        components: {},
        data() {
            return {
                username: "",
                password: "",
                login: false
            };
        },
        watch: {},
        vuex: {
            getters: {
                ui,
                userInfo,
                popPerfect
            },
            actions: {
                setUi,
                setUserInfo,
                setpopPerfect
            }
        },
        methods: {
            onSubmit(e) {
                let me = this;
                if (me.login) {
                    if (me.username != "" && me.password != "") {
                        me.service.userLogin(me, info => {
                            me.$router.push({
                                path: "/"
                            });
                        });
                        // me.onfullScreen();
                    } else {
                        layer.alert("账号或密码不能为空");
                    }
                } else {
                    layer.alert("此收款台未绑定，请联系系统管理员!");
                }
            },
            onfullScreen() {
                var docElm = document.documentElement;
                //W3C  
                if (docElm.requestFullscreen) {
                    docElm.requestFullscreen();
                }
                //FireFox  
                else if (docElm.mozRequestFullScreen) {
                    docElm.mozRequestFullScreen();
                }
                //Chrome等  
                else if (docElm.webkitRequestFullScreen) {
                    docElm.webkitRequestFullScreen();
                }
                //IE11
                else if (elem.msRequestFullscreen) {
                    elem.msRequestFullscreen();
                }
            }
        },
        mounted() {
            let me = this;

            function loginHeight() {
                let winHeight = $(document).innerHeight();
                let login = $('.teamplate-login');
                login.css('height', winHeight);
                console.log($(window).innerHeight());
            }

            $(window).resize(function() {
                loginHeight();
            })
            loginHeight();
            me.myCat = localStorage.getItem("myCat");
            var parms = {
                macAddress: me.myCat
            };
            console.log(parms);
            $.ajax({
                type: "POST",
                url: me.cfg.api + "/ls/validateSktidAndMac",
                data: parms
            }).done(data => {
                console.log(data);
                if (data.code == 200) {
                    localStorage.setItem("sktId", data.data.sktid);
                    me.login = true;
                } else {
                    layer.alert("此收款台未设置，请联系技术人员!")
                }
            });
            console.log(me.login);

            $(document).keydown(function(e) {
                let key = e.keyCode;
                if (key == 13) {
                    me.onSubmit();
                }
            })
        },
        beforeDestroy() {
            let me = this;
            history.go(0);
        }
    };
</script>